import {
    reqMergeChunks, reqUploadChunk, reqCheckChunk, reqFolderFile, reqSaveFolder,
    reqFileblob, reqSaveShareFile, reqMyShareFile, reqCancelShare, reqDeleteFile,
    reqShareFile, reqCheck, reqShareInfo, reqFile, reqFolderList, reqFileTag,
    reqSaveFileTag, reqSaveFileToMe
} from "@/api"
// state：仓库存储数据的地方
const state = {
    fileList: [],
}
// mutations：修改state的唯一手段，因此第一个参数必须是state，第二个参数为将要修改的数据
const mutations = {
    SET_FILELIST(state, res) {
        res.forEach(function (obj) {
            obj.show = false;
            obj.isEdit = false;
        });
        state.fileList = state.fileList.concat(res)
    },
    CLEAR_FILELIST(state, res) {
        state.fileList = []
    },
}
// action：书写业务逻辑（method方法）
const actions = {
    async mergeChunks({ commit }, data) {
        return await reqMergeChunks(data)
    },
    async uploadChunk({ commit }, data) {
        return await reqUploadChunk(data)
    },
    async checkChunk({ commit }, data) {
        return await reqCheckChunk(data)
    },
    async getFolderFile({ commit }, data) {
        let res = await reqFolderFile(data)
        // if (res.success) commit("SET_FILELIST", res.data.list)
        return res
    },
    async saveFolder({ commit }, data) {
        return await reqSaveFolder(data)
    },
    async getFileblob({ commit }, data) {
        return await reqFileblob(data)
    },
    // 保存分享的文件
    async saveShareFile({ commit }, data) {
        return await reqSaveShareFile(data)
    },
    // 获取自己分享的文件(全部)
    async getMyShareFile({ commit }, data) {
        return await reqMyShareFile(data)
    },
    async cancelShare({ commit }, data) {
        return await reqCancelShare(data)
    },
    async getDeleteFile({ commit }, data) {
        return await reqDeleteFile(data)
    },
    async getShareFile({ commit }, data) {
        return await reqShareFile(data)
    },
    async getCheck({ commit }, data) {
        return await reqCheck(data)
    },
    async getShareInfo({ commit }, data) {
        return await reqShareInfo(data)
    },
    async getFile({ commit }, id) {
        return await reqFile(id)
    },
    async getFolderList({ commit }, data) {
        return await reqFolderList(data)
    },
    async getFileTag({ commit }, data) {
        return await reqFileTag(data)
    },
    async saveFileTag({ commit }, data) {
        return await reqSaveFileTag(data)
    },
    async saveFileToMe({ commit }, data) {
        return await reqSaveFileToMe(data)
    },
}
// getters：计算属性
const getters = {

}

export default {
    state,
    mutations,
    actions,
    getters
}